//2009/09/10 15:33:01
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>

using namespace std;

class TheCardShufflingDivTwo
{
public:
    int shuffle(int n, int m)
    {
        int ret = 1;
        do
        {
            ret *= 2;
            if (n%2==0) n++;
            ret %= n;
            m--;
        }
        while (m);
		if(n == 1) return 1;
		return ret;
    }
};
